package artid.com.arttogoa.adapter;

import java.util.List;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import artid.com.arttogoa.R;
import artid.com.arttogoa.parser.TransactionRecordParser;
import artid.com.arttogoa.util.VeDate;

/**
 * 
 *    
 * 项目名称：ArtworkArtA   
 * 类名称   ：TransactionRecord_Adapter   
 * 类描述   ：交易记录适配器(也叫账单)   
 * 创建人   ：耿卫斌   
 * 创建时间：2016-7-19 下午4:04:10   
 *
 */
public class TransactionRecord_Adapter extends BaseAdapter{
	private Context mContext;
	private List<TransactionRecordParser> list;
	private int  whichActivity=0;//从哪个页面的适配器(0:全部 1：收入 2:支出)                                                       

	public TransactionRecord_Adapter(Context mContext,
			List<TransactionRecordParser> list, int whichActivity) {
		super();
		this.mContext = mContext;
		this.list = list;
		this.whichActivity = whichActivity;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		//		return list.size();
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;
		View v = convertView;
		if (v == null) {
			holder = new ViewHolder();
			v = LayoutInflater.from(mContext).inflate(R.layout.item_transactionrecord, null);
			holder.title=(TextView) v.findViewById(R.id.item_transactionrecord_title);
			holder.price=(TextView) v.findViewById(R.id.item_transactionrecord_price);
			holder.time=(TextView) v.findViewById(R.id.item_transactionrecord_time);
			holder.operation=(TextView) v.findViewById(R.id.item_transactionrecord_operation);
			v.setTag(holder);
		} else {
			holder = (ViewHolder) v.getTag();
		}
		if(whichActivity==0){
			holder.title.setText("全部适配器");
		}else if(whichActivity==1){
			holder.title.setText("收入适配器");
		}else if(whichActivity==2){
			holder.title.setText("支出适配器");
		}
		holder.title.setText(list.get(position).getDesc());
		holder.time.setText(VeDate.formatUnixTime(list.get(position).getDeal_time()));
		String income_state=list.get(position).getIncome_state();
		if("0".equals(income_state)){
			//收入
			holder.price.setText("+"+list.get(position).getAmount());
			holder.price.setTextColor(Color.parseColor("#42D765"));
		}else if("2".equals(income_state)){
			//支出
			holder.price.setText(list.get(position).getAmount());
			holder.price.setTextColor(Color.parseColor("#FF4331"));
		}
		String deal_state=list.get(position).getDeal_state();
		if("0".equals(deal_state)){
			//失败
			holder.operation.setText("交易失败");
		}else if("1".equals(deal_state)){
			//成功
			holder.operation.setText("交易成功");
		}
		return v;
	}
	class ViewHolder {
		TextView title,price,time,operation;
	}
}
